﻿using System;
using System.Web.UI;

namespace WebDiagnostics
{
    public static class HtmlTextWriterExtensions
    {

        public static void RenderBeginTag(this HtmlTextWriter writer, HtmlTextWriterTag tag, string @class = null)
        {
            if(@class != null)
                writer.AddAttribute(HtmlTextWriterAttribute.Class, @class);

            writer.RenderBeginTag(tag);
        }

        public static void RenderBeginDiv(this HtmlTextWriter writer, string @class = null)
        {
            writer.RenderBeginTag(HtmlTextWriterTag.Div, @class);
        }

        public static void RenderHeader(this HtmlTextWriter writer, int level, string text, string @class = null)
        {
            var tag = (HtmlTextWriterTag) Enum.Parse(typeof (HtmlTextWriterTag), "H" + level);
            writer.RenderBeginTag(tag, @class);
            writer.Write(text);
            writer.RenderEndTag();
        }

        public static void RenderBeginList(this HtmlTextWriter writer, string @class = null)
        {
            writer.RenderBeginTag(HtmlTextWriterTag.Ul, @class);
        }

        public static void RenderBeginListItem(this HtmlTextWriter writer, string @class = null)
        {
            writer.RenderBeginTag(HtmlTextWriterTag.Li, @class);
        }

        public static void RenderStylesheetInclude(this HtmlTextWriter writer, string url)
        {
            writer.WriteLine("<link rel=StyleSheet href='{0}' type='text/css' >", url);
        }



    }
}
